package com.trkj.service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.trkj.dao.jpa.IjlElectronicePrintDAO;
import com.trkj.pojos.JlElectronicePrint;


@Service
@Transactional
public class JlJlElectronicePrintService {
	@Autowired
	private IjlElectronicePrintDAO ElectronicePrintDAO;
	/*
	 * 查看开药信息
	 */
	public Map<String, Object> queryreginByPage(int page, int rows){
		PageRequest pr = new PageRequest(page - 1, rows);
		//获取当前页的记录
		List<JlElectronicePrint> list = ElectronicePrintDAO.findElectronicePrintByPage(pr);		
		//获取总的记录条数
		long total = ElectronicePrintDAO.count();		
		Map<String, Object> map = new HashMap<>();
		map.put("total", total);
		map.put("rows", list);
		return map;
	}
	//查找最大的开药编号
	public  long findMaxelePritid(){
		return ElectronicePrintDAO.findMaxelePritid();
	}
	//添加电子处方总表信息
	public void  addJlElectronicePrint( Date erOpenTime, BigDecimal ierId,BigDecimal adviceId ,String erPhysician, String inpectionResult,String state,BigDecimal rerId){
		JlElectronicePrint ElectronicePrint=new JlElectronicePrint();
		ElectronicePrint.setAdviceId(adviceId);
		ElectronicePrint.setErOpenTime(erOpenTime);
		ElectronicePrint.setErPhysician(erPhysician);
		ElectronicePrint.setIerId(ierId);
		ElectronicePrint.setInpectionResult(inpectionResult);
		ElectronicePrint.setState(state);
		ElectronicePrint.setRerId(rerId);
		ElectronicePrintDAO.save(ElectronicePrint);
	}
	//根据最大的编号查找当天的日期
	public  Date MaxelePritidToDate(Long erId){
		return ElectronicePrintDAO.MaxelePritidToDate(erId);
	}
	public  List<JlElectronicePrint> idToElectronicePrint(Long ierId){
		BigDecimal ZierId=new BigDecimal(ierId);
		return ElectronicePrintDAO.idToElectronicePrint(ZierId);
	}
	
}
